import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

// 路由配置
const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/list'
  },
  {
    path: '/list',
    name: 'CircuitDiagramList',
    component: () => import('@/views/CircuitDiagramList.vue'),
    meta: {
      title: '一次图列表'
    }
  },
  {
    path: '/draw',
    name: 'CircuitDiagramDraw',
    component: () => import('@/views/CircuitDiagramDraw.vue'),
    meta: {
      title: '一次图绘制'
    }
  },
  {
    path: '/manage',
    name: 'DeviceManage',
    component: () => import('@/views/DeviceManage.vue'),
    meta: {
      title: '设备图管理'
    }
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  // 设置页面标题
  if (to.meta.title) {
    document.title = `${to.meta.title} - 一次图画图工具`
  }
  next()
})

export default router 